{include file='/public/header'}
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">轮播管理</a>
        <a>
          <cite>近期特惠</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
        <div class="layui-carousel" id="carousel">
          <div carousel-item>
            <div><img src="{$data.imga}"></div>
            <div><img src="{$data.imgb}"></div>
            <div><img src="{$data.imgc}"></div>
            <div><img src="{$data.imgd}"></div>
            <div><img src="{$data.imge}"></div>
          </div>
        </div>
        <blockquote class="layui-elem-quote">请注意上传更换图片只能是382 X 255 像素的图片<i class="layui-icon x-show" status='true'>&#xe623;</i></blockquote>
        <form class="layui-form">
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图片1</label>
            <div class="layui-input-inline">
              <button type="button" class="layui-btn" id="test1" onclick="return false;">
              <i class="layui-icon">&#xe67c;</i>更换图片
            </button>
            <hr class="hr15">
            <img id="imga" <?php if($data['imga']){echo 'src="'.$data['imga'].'"';}?>>
            <input type="hidden" name="imga" value="{$data.imga}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图片2</label>
            <div class="layui-input-inline">
              <button type="button" class="layui-btn" id="test2" onclick="return false;">
              <i class="layui-icon">&#xe67c;</i>更换图片
            </button>
            <hr class="hr15">
            <img id="imgb" <?php if($data['imgb']){echo 'src="'.$data['imgb'].'"';}?>>
            <input type="hidden" name="imgb" value="{$data.imgb}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图片3</label>
            <div class="layui-input-inline">
              <button type="button" class="layui-btn" id="test3" onclick="return false;">
              <i class="layui-icon">&#xe67c;</i>更换图片
            </button>
            <hr class="hr15">
            <img id="imgc" <?php if($data['imgc']){echo 'src="'.$data['imgc'].'"';}?>>
            <input type="hidden" name="imgc" value="{$data.imgb}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图片4</label>
            <div class="layui-input-inline">
              <button type="button" class="layui-btn" id="test4" onclick="return false;">
              <i class="layui-icon">&#xe67c;</i>更换图片
            </button>
            <hr class="hr15">
            <img id="imgd" <?php if($data['imgd']){echo 'src="'.$data['imgd'].'"';}?>>
            <input type="hidden" name="imgd" value="{$data.imgd}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图片5</label>
            <div class="layui-input-inline">
              <button type="button" class="layui-btn" id="test5" onclick="return false;">
              <i class="layui-icon">&#xe67c;</i>更换图片
            </button>
            <hr class="hr15">
            <img id="imge" <?php if($data['imge']){echo 'src="'.$data['imge'].'"';}?>>
            <input type="hidden" name="imge" value="{$data.imge}">
            </div>
          </div>
      </form>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" onclick="save()">保存</button>
        </div>
      </div>
    </div>
    <script>
      layui.use(['layer','form','upload','carousel'], function(){
        $ = layui.jquery;
        layer = layui.layer;
        form = layui.form;
        var upload = layui.upload;
        var carousel = layui.carousel;

        carousel.render({
          elem: '#carousel'
          ,width: '382px' //设置容器宽度
          ,arrow: 'always' //始终显示箭头
        });

        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '{:url("carousel/upload_img")}' //上传接口
            ,accept:'images'
            ,done: function(res){
              //上传完毕回调
              $('#imga').attr('src',res.msg);
              $('input[name="imga"]').val(res.msg);
            }
            ,error: function(){
              //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#test2' //绑定元素
            ,url: '{:url("carousel/upload_img")}' //上传接口
            ,accept:'images'
            ,done: function(res){
              //上传完毕回调
              $('#imgb').attr('src',res.msg);
              $('input[name="imgb"]').val(res.msg);
            }
            ,error: function(){
              //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#test3' //绑定元素
            ,url: '{:url("carousel/upload_img")}' //上传接口
            ,accept:'images'
            ,done: function(res){
              //上传完毕回调
              $('#imgc').attr('src',res.msg);
              $('input[name="imgc"]').val(res.msg);
            }
            ,error: function(){
              //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#test4' //绑定元素
            ,url: '{:url("carousel/upload_img")}' //上传接口
            ,accept:'images'
            ,done: function(res){
              //上传完毕回调
              $('#imgd').attr('src',res.msg);
              $('input[name="imgd"]').val(res.msg);
            }
            ,error: function(){
              //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#test5' //绑定元素
            ,url: '{:url("carousel/upload_img")}' //上传接口
            ,accept:'images'
            ,done: function(res){
              //上传完毕回调
              $('#imge').attr('src',res.msg);
              $('input[name="imge"]').val(res.msg);
            }
            ,error: function(){
              //请求异常回调
            }
        });
      });
      //保存
      function save(){
        $.post('{:url("carousel/recent_save")}',$('form').serialize(),function(res){
          if(res.code>0){
            layer.msg(res.msg,{'icon':2,'anim':2});
          }else{
            layer.msg(res.msg,{'icon':1});
            setTimeout(function(){window.location.reload();},1000);
          }
        },'json');
      }
    </script>

</html>